home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 424_01 / ed_157 / bigger_win.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-11-06  |  4.3 KB  |  158 lines

  1. /*
  2.  * Copyright (C) 1992 by Rush Record
  3.  * Copyright (C) 1993 by Charles Sandmann (sandmann@clio.rice.edu)
  4.  * 
  5.  * This file is part of ED.
  6.  * 
  7.  * ED is free software; you can redistribute it and/or modify it under the terms
  8.  * of the GNU General Public License as published by the Free Software Foundation.
  9.  * 
  10.  * ED is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  11.  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  12.  * PARTICULAR PURPOSE.  See the GNU General Public License for more details.
  13.  * 
  14.  * You should have received a copy of the GNU General Public License along with ED
  15.  * (see the file COPYING).  If not, write to the Free Software Foundation, 675
  16.  * Mass Ave, Cambridge, MA 02139, USA.
  17.  */
  18. #include "opsys.h"
  19.  
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include <string.h>
  23.  
  24. #include "rec.h"
  25. #include "window.h"
  26. #include "ed_dec.h"
  27. #include "handy.h"
  28.  
  29. /******************************************************************************\
  30. |Routine: bigger_window
  31. |Callby: command
  32. |Purpose: Increases the size of a window.
  33. |Arguments:
  34. |    increase - the number of lines to add to the window.
  35. \******************************************************************************/
  36. void bigger_window(increase)
  37. Int increase;
  38. {
  39.     Int i,j,space,topavail,botavail,topgrab,botgrab,excess,trim;
  40.     rec_ptr r;
  41.     
  42.     if(NWINDOWS == 1)
  43.         return;
  44.     save_window();
  45. /* get the amount available above and below */
  46.     for(topavail = botavail = i = 0;i < NWINDOWS;i++)
  47.         if((excess = WINDOW[i].botrow - WINDOW[i].toprow - 2))
  48.         {
  49.             if(i < CURWINDOW)
  50.                 topavail += excess;
  51.             if(i > CURWINDOW)
  52.                 botavail += excess;
  53.         }
  54.     increase = min(increase,topavail + botavail);
  55. /* allocation algorithm CWS 10-93; split equally, then fix for availability */
  56.     topgrab = increase >> 1;
  57.     botgrab = increase - topgrab;
  58.     /* if not enough room to expand bottom, glom it with top */
  59.     if((i = botgrab - botavail) > 0)
  60.     {
  61.         topgrab += i;
  62.         botgrab = botavail;
  63.     }
  64.     else if((i = topgrab - topavail) > 0)
  65.     {
  66.         topgrab = topavail;
  67.         botgrab += i;
  68.     }
  69.     if((space = topgrab))
  70.     {
  71.         for(i = CURWINDOW - 1;i >= 0;i--)    /* start with previous window */
  72.         {
  73.             if((excess = WINDOW[i].botrow - WINDOW[i].toprow - 2))
  74.             {
  75.                 trim = min(space,excess);
  76.                 if(i < CURWINDOW - 1)    /* del_line not necessary on first borrow, ref_window takes care of that */
  77.                 {
  78.                     marge(1,NROW);
  79.                     move(WINDOW[i].botrow - trim + 1,1);
  80.                     del_line(trim);
  81.                     move(WINDOW[CURWINDOW].toprow,1);
  82.                     ins_line(trim);
  83.                 }
  84.                 WINDOW[CURWINDOW].toprow -= trim;
  85.                 WINDOW[CURWINDOW].currow -= trim;
  86.                 WINDOW[i].botrow -= trim;
  87.                 new_botrec(i);
  88.                 calc_limits(WINDOW[i].toprow,WINDOW[i].botrow,&WINDOW[i].toplim,&WINDOW[i].botlim);
  89.                 if(WINDOW[i].currow > WINDOW[i].botlim)
  90.                 {
  91.                     j = CURWINDOW;
  92.                     set_window(i);
  93.                     CURROW -= scroll_up(CURROW - BOTLIM);
  94.                     save_window();
  95.                     set_window(j);
  96.                 }
  97.                 for(j = i + 1;j < CURWINDOW;j++)
  98.                 {
  99.                     WINDOW[j].toprow -= trim;
  100.                     WINDOW[j].botrow -= trim;
  101.                     WINDOW[j].toplim -= trim;
  102.                     WINDOW[j].botlim -= trim;
  103.                     WINDOW[j].currow -= trim;
  104.                 }
  105.                 if(!(space -= trim))
  106.                     break;
  107.             }
  108.         }
  109.     }
  110.     if((space = botgrab))
  111.     {
  112.         for(i = NWINDOWS - 1;i > CURWINDOW;i--)    /* start with bottom window */
  113.         {
  114.             if((excess = WINDOW[i].botrow - WINDOW[i].toprow - 2))
  115.             {
  116.                 trim = min(space,excess);
  117.                 marge(1,NROW);
  118.                 move(WINDOW[CURWINDOW].botrow + 1,1);
  119.                 ins_line(trim);
  120.                 WINDOW[CURWINDOW].botrow += trim;
  121.                 WINDOW[i].toprow += trim;
  122.                 WINDOW[i].currow += trim;
  123.                 new_botrec(i);
  124.                 calc_limits(WINDOW[i].toprow,WINDOW[i].botrow,&WINDOW[i].toplim,&WINDOW[i].botlim);
  125.                 if(WINDOW[i].currow > WINDOW[i].botlim)
  126.                 {
  127.                     j = CURWINDOW;
  128.                     set_window(i);
  129.                     CURROW -= scroll_up(CURROW - BOTLIM);
  130.                     save_window();
  131.                     set_window(j);
  132.                 }
  133.                 for(j = i - 1;j > CURWINDOW;j--)
  134.                 {
  135.                     WINDOW[j].toprow += trim;
  136.                     WINDOW[j].botrow += trim;
  137.                     WINDOW[j].toplim += trim;
  138.                     WINDOW[j].botlim += trim;
  139.                     WINDOW[j].currow += trim;
  140.                 }
  141.                 if(!(space -= trim))
  142.                     break;
  143.             }
  144.         }
  145.     }
  146.     new_botrec(CURWINDOW);
  147.     calc_limits(WINDOW[CURWINDOW].toprow,WINDOW[CURWINDOW].botrow,&WINDOW[CURWINDOW].toplim,&WINDOW[CURWINDOW].botlim);
  148.     set_window(CURWINDOW);
  149.     ref_window(CURWINDOW);
  150.     fix_display();
  151.     if(!BOTREC)
  152.     {
  153.         for(i = 0,r = TOPREC;r != BASE;r = r->next,i++);
  154.         CURROW += scroll_down(BOTROW - TOPROW - i);
  155.     }
  156. }
  157.  
  158.